﻿// author : @azyobuzin
namespace  Codeplex.KinkumaFramework.Interactivity
{
    using System.Diagnostics;
    using System.Windows;
    using System.Windows.Interactivity;
    using Microsoft.Practices.Prism.Interactivity.InteractionRequest;

    /// <summary>
    /// プロセスの起動を行うアクションです。
    /// </summary>
    [DefaultTrigger(typeof(DependencyObject), typeof(InteractionRequestTrigger), null)]
    public class StartProcessAction : TriggerAction<DependencyObject>
    {
        public static readonly DependencyProperty FileNameProperty =
            DependencyProperty.Register("FileName", typeof(string), typeof(StartProcessAction));

        public static readonly DependencyProperty ArgumentsProperty =
            DependencyProperty.Register("Arguments", typeof(string), typeof(StartProcessAction));

        /// <summary>
        /// 起動プロセス名
        /// </summary>
        public string FileName
        {
            set
            {
                this.SetValue(FileNameProperty, value);
            }
            get
            {
                return (string)this.GetValue(FileNameProperty);
            }
        }

        /// <summary>
        /// プロセスの実行時引数
        /// </summary>
        public string Arguments
        {
            set
            {
                this.SetValue(ArgumentsProperty, value);
            }
            get
            {
                return (string)this.GetValue(ArgumentsProperty);
            }
        }

        protected override void Invoke(object parameter)
        {
            Process.Start(this.FileName, this.Arguments);
        }
    }
}
